package org.example.aienglishapp.controller.progress;

import org.example.aienglishapp.entity.progress.DailyGoal;
import org.example.aienglishapp.service.progress.DailyGoalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequestMapping("/api/daily-goals")
public class DailyGoalController {

    @Autowired
    private DailyGoalService dailyGoalService;

    // 根据用户 ID 获取目标
    @GetMapping("{user_id}")
    public ResponseEntity<List<DailyGoal>> getGoalsByUserId(@PathVariable("user_id") Long userId) {
        List<DailyGoal> goals = dailyGoalService.getGoalsByUserId(userId);
        return ResponseEntity.ok(goals);
    }

    // 添加新目标
    @PostMapping
    public ResponseEntity<DailyGoal> addGoal(@RequestBody DailyGoal dailyGoal) {
        DailyGoal newGoal = dailyGoalService.addGoal(dailyGoal);
        return ResponseEntity.status(201).body(newGoal);
    }

    // 更新目标
    @PutMapping("/{id}")
    public ResponseEntity<DailyGoal> updateGoal(@PathVariable Long id, @RequestBody DailyGoal updatedGoal) {
        DailyGoal goal = dailyGoalService.updateGoal(id, updatedGoal);
        return ResponseEntity.ok(goal);
    }

    // 删除目标
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteGoal(@PathVariable Long id) {
        dailyGoalService.deleteGoal(id);
        return ResponseEntity.noContent().build();
    }
}